<%--
功能: 批量上传组件
http://plugins.jquery.com/project/ocupload 
--%>
<%@ tag body-content="empty"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ attribute name="fileInputId" required="true" description="按钮DOMid"%>
<%@ attribute name="fileQueueId" required="false" description="文件队列div的id,用于显示上传进度，默认为false（不显示）"%>
<%@ attribute name="multi" required="false" description="是否允许上传多个文件，默认false（不允许多个）"%>

<%@ attribute name="uploadCategory" required="false" description="输入上传的目录名,如category,product等,对应前台media下的目录,默认是others目录"%>

<%@ attribute name="fileDesc" required="false" description="对话框上的文件类型显示的文字"%>
<%@ attribute name="fileExt" required="false" description="上传文件格式，形如: *.ext1;*.ext2;*.ext3"%>

<%@ attribute name="buttonImg" required="false" description="按钮图片"%>
<%@ attribute name="width" required="false" description="按钮图片宽度"%>
<%@ attribute name="height" required="false" description="按钮图片高度"%>

<%@ attribute name="onComplete" required="false" description="当上传完毕后，调用的回调函数"%>
<%@ attribute name="onSelect" required="false" description="浏览文件后，调用的回调函数"%>

<c:set var="plugin_newUpload" value="true" scope="request"/>
<c:if test="${empty uploadCategory}">
	<c:set var="uploadCategory" value="others" scope="page"/>
</c:if>

<c:if test="${not empty fileQueueId}">
	<c:set var="fileQueueId" value="${fileQueueId}" scope="page"/>		
</c:if>
<c:if test="${empty fileQueueId}">
	<c:set var="fileQueueId" value="false" scope="page"/>		
</c:if>
		
<c:if test="${empty buttonImg}">
	<c:set var="buttonImg" value="${ctxPath}/images/btn/uploadimg_btn1.png" scope="page"/>
</c:if>
<c:if test="${empty width}">
	<c:set var="width" value="96" scope="page"/>
</c:if>
<c:if test="${empty height}">
	<c:set var="height" value="20" scope="page"/>
</c:if>
<c:if test="${empty multi}">
	<c:set var="multi" value="false" scope="page"/>
</c:if>

<script type="text/javascript" defer>
$j(document).ready(function () {
	//必须在scriptData中带JSESSIONID（否则firefox获取不了session），并且method设为get（否则ie获取不了scriptData）。
	$j("#${fileInputId}").uploadify({
		uploader         : '${ctxPath}/scripts/plugins/uploadify/uploadify.swf',
		script           : escape('${ctxPath}/newUpload.html;JSESSIONID=<%=request.getSession().getId()%>?11&'),  //必须使用escape对&进行编码，且必须放在script中。
		scriptData       :  {   
								'returnJSON':'true',
								'uploadCategory':'${uploadCategory}',
								'onCompleteHandler':'${onComplete}',
								'fileInputId':'${fileInputId}'
							},
		fileDataName	 : '${fileInputId}',			
		method           : 'GET',  
		cancelImg        : '${ctxPath}/scripts/plugins/uploadify/cancel.png',
		buttonImg        : '${buttonImg}',
		width            : ${width},
		height           : ${height},
		queueID          : '${fileQueueId}',
		wmode            : 'transparent',
		scriptAccess     : 'always',
		auto             : true,
		multi            : ${multi},
	<c:if test="${not empty fileDesc}">
		fileDesc         : '${fileDesc}',
	</c:if>
	<c:if test="${not empty fileExt}">
		fileExt         : '${fileExt}',
	</c:if>
		fileExt          : '*.jpg',
		onError          : function(event,queueID,fileObj,errorObj){
								alert('error'+errorObj);
						   },
		onComplete       : function(event, ID, fileObj, response, data){
								var result = eval('('+response+')');
								if(result.uploadedFiles!=undefined && result.uploadedFiles!=null){
									for(var i=0; i<result.uploadedFiles.length; i++){
										${onComplete}(result.uploadedFiles[i],response.fileInputId);
										$(result.fileInputId).value = result.uploadedFiles[i];
									}
								}
								if(result.uploadMsg!=undefined && result.uploadMsg!=null){
									if(result.uploadMsg == 'err001'){
										alert(__FMT.error_upload_err001);
									}
									if(result.uploadMsg == 'err002'){
										alert(__FMT.error_upload_err002);
									}
								}
		
						   }
	});
	

});
</script>